package com.dmcloud.dm.auth.Exception;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializerProvider;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.IOException;

/**
 * Created by xiaodao
 * date: 2020/5/6
 */
public class MyOAuthExceptionJacksonSerializer extends JsonSerializer<MyOAuth2Exception> {

    @Autowired
    private ObjectMapper objectMapper;


    @Override
    public void serialize(MyOAuth2Exception e, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        jsonGenerator.writeStartObject();
        jsonGenerator.writeObjectField("code",e.getHttpErrorCode());
        jsonGenerator.writeObjectField("msg",e.getMessage());
        jsonGenerator.writeObjectField("data","");

        jsonGenerator.writeEndObject();
    }
}
